﻿using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Win32;
using HeerMusic.UserControls;

namespace HeerMusic
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        MediaPlayer mp = new MediaPlayer();
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                // ListBox1.Items.Add(openFileDialog.FileName);
                MusicListItem musicitem = new MusicListItem();


                UserControls.Music mu = new UserControls.Music() {Name=openFileDialog.SafeFileName,Uri=openFileDialog.FileName };
                musicitem.Music = mu;
                listBoxMusic.Items.Add(musicitem);

               
            }
            
        }

       

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {

            if (mp.HasAudio)
            {
                switch (_233.Content)
                {
                    case "\xE103":

                        mp.Pause();
                        _233.Content = "\xE102";
                        break;
                    case "\xE102":
                        mp.Play();
                        _233.Content = "\xE103";
                        break;
                }
            }
            else {
                if (listBoxMusic.SelectedItem != null)
                {
                    _233.Content = "\xE103";
                    var Temp = (MusicListItem)listBoxMusic.SelectedItem;

                    Uri uri = new Uri(Temp.Music.Uri);
                    mp.Open(uri);
                    mp.Play();
                    time.Text = mp.Position.ToString();
                }
            }
            
            
        }

        private void btn_next_Click(object sender, RoutedEventArgs e)
        {
            mp.Close();
            var a = listBoxMusic.SelectedIndex + 1;

            if ( a>= 0 && a< (listBoxMusic.Items.Count))
            {
                listBoxMusic.SelectedIndex++;
                var Temp = (MusicListItem)listBoxMusic.Items[listBoxMusic.SelectedIndex];

                Uri uri = new Uri(Temp.Music.Uri);
                mp.Open(uri);
                mp.Play();
                time.Text = mp.Position.ToString();
            }
        }

        private void listBoxMusic_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            
            
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var s = text1.Text;
            var qwq=NeteasyMusic.Music.GetSearch("Befall", "2", "1");
            foreach (var item in qwq)

            {
                listBoxMusic.Items.Add(item.url);
            }

        }
    }
}
